﻿using CommonNet48.SerializerUtils;
using DBOptionPro.Model;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DBOptionPro.BLL
{
    /// <summary>
    /// 文件搜索业务逻辑处理类
    /// </summary>
    public class DBInfoFileBLL
    {
        /// <summary>
        /// 搜索的文件本地保存路径
        /// </summary>
        private readonly string _File = Path.Combine(AppContext.BaseDirectory, "Config", "DBFileInfo.json");

        /// <summary>
        /// 文件列表
        /// </summary>
        private List<DBFileInfo> _Files;

        /// <summary>
        /// 获取文件列表
        /// </summary>
        /// <returns></returns>
        public List<DBFileInfo> GetFiles()
        {
            if (_Files == null)
            {
                _Files = JsonHelper.JsonFileToObject<List<DBFileInfo>>(_File);
                if (_Files == null) _Files = new List<DBFileInfo>();
            }
            return _Files;
        }

        /// <summary>
        /// 保存文件列表
        /// </summary>
        /// <param name="files"></param>
        public void SaveFiles(List<DBFileInfo> files)
        {
            JsonHelper.ObjectToJsonFile(files, _File);
            _Files = files;
        }
    }
}
